package com.itheima.d6_tcp3;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;

public class Server {
    //创建一个静态集合
    public static ArrayList<Socket> onlineSocket = new ArrayList<>();
    public static void main(String[] args) throws Exception {
        //1.创建服务端对象
        System.out.println("服务端启动了...");
        ServerSocket ss = new ServerSocket(8888);
        //2.监听客户端
        System.out.println("等待客户端连接...");
        while (true) {
            Socket socket = ss.accept();
            System.out.println("一个客户端连接成功...IP地址是:" +socket.getInetAddress().getHostAddress());
            //每连接一个客户端 就添加到集合中
            onlineSocket.add(socket);
            //创建一个线程
            new MyThread(socket).start();
        }


    }
}
